//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>
package org.jpgolay.wi.diary;

import java.awt.Dimension;
import java.awt.event.*;
import java.beans.PropertyVetoException;
import java.math.BigDecimal;
import java.util.*;
import javax.swing.*;
import org.jpgolay.gui.fixed.*;
import org.jpgolay.gui.iconBar.*;
import org.jpgolay.wi.availability.Availability;
import org.jpgolay.wi.availability.AvailabilityGUI;
import org.jpgolay.wi.customer.*;
import org.jpgolay.wi.persistence.ObjectCRUD;
import org.jpgolay.wi.realestate.RealEstate;
import org.jpgolay.wi.realestate.RealEstatePanelGUI;
import org.jpgolay.wi.util.*;

// Referenced classes of package org.jpgolay.wi.diary:
//            DiaryGUI, DiaryDetailsPanelGUI
public class DiaryController extends DiaryGUI {

    private class MouseClickCustomerList extends MouseAdapter {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                actionCustomerLoad((String) getCustomerTableViewer().getTable().getValueAt(getCustomerTableViewer().getTable().getSelectedRow(), 0));
            }
        }

        MouseClickCustomerList() {
        }
    }

    private class MouseClickRealEstateList extends MouseAdapter {

        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                initField();
                actionRealEstateLoad((String) getRealEstateTableViewer().getTable().getValueAt(getRealEstateTableViewer().getTable().getSelectedRow(), 0));
            }
        }

        MouseClickRealEstateList() {
        }
    }

    private class MouseClickDiaryList extends MouseAdapter {

        public void mouseClicked(MouseEvent e) {
            e.getClickCount();
        }

        MouseClickDiaryList() {
        }
    }

    public DiaryController(Parameter param) {
        create = false;
        write = false;
        this.param = param;
        crud = new ObjectCRUD();
        customerCrud = new CustomerCRUD();
        green = new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/green12x12.png"));
        orange = new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/orange12x12.png"));
        red = new ImageIcon(getClass().getResource("/org/jpgolay/wi/images/red12x12.png"));
        d = new WIDate();
        initLaw();
        initMenu();
        initIconBar();
        initField();
        initCustomerSearch();
        initCustomerTable();
        initRealEstateSearch();
        initRealEstateTable();
        initDiaryTable();
    }

    private void initLaw() {
        write = true;
    }

    private void initMenu() {
        getMenuPanel().getExit().addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                actionExit();
            }
        });
        getMenuPanel().getDelete().addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                actionRemove();
            }
        });
        getMenuPanel().getHelp().addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                actionHelp();
            }
        });
        getMenuPanel().getModify().addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                actionModify();
            }
        });
        getMenuPanel().getNew().addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                actionNew();
            }
        });
        getMenuPanel().getOpen().addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent actionevent) {
            }
        });
        getMenuPanel().getPrint().addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                actionPrint(true);
            }
        });
        getMenuPanel().getSave().addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                actionSave();
            }
        });
    }

    private void initIconBar() {
        getIconBarPanel().addAnswerListener(new AnswerListener() {
            public void create(AnswerEvent e) {
                actionNew();
            }

            public void open(AnswerEvent answerevent) {
            }

            public void modify(AnswerEvent e) {
                actionModify();
            }

            public void save(AnswerEvent e) {
                actionSave();
            }

            public void remove(AnswerEvent e) {
                actionRemove();
            }

            public void print(AnswerEvent e) {
                actionPrint(false);
            }

            public void help(AnswerEvent e) {
                actionHelp();
            }
        });
    }

    private void initField() {
        cleanField();
        setEnabledField(false);
        getIconBarPanel().setEnabledCreate(write);
        getIconBarPanel().setEnabledSave(false);
        getIconBarPanel().setEnabledModify(false);
        getIconBarPanel().setEnabledRemove(false);
        getIconBarPanel().setEnabledPrint(false);
        getIconBarPanel().setEnabledOpen(false);
        getMenuPanel().getNew().setEnabled(write);
        getMenuPanel().getSave().setEnabled(false);
        getMenuPanel().getModify().setEnabled(false);
        getMenuPanel().getDelete().setEnabled(false);
        getMenuPanel().getPrint().setEnabled(false);
        getMenuPanel().getOpen().setEnabled(false);
        create = false;
        plainYearStatus = new int[365];
        leapYearStatus = new int[366];
        for (int i = 0; i < 365; i++) {
            plainYearStatus[i] = 0;
        }

        for (int i = 0; i < 366; i++) {
            leapYearStatus[i] = 0;
        }

        plainYearCustomer = new String[365];
        leapYearCustomer = new String[366];
        getDiaryDetailsPanel().getRealEstatePanel().initFields();
        getDiaryDetailsPanel().getCustomerPanel().initFields();
    }

    private void initCustomerSearch() {
        getCustomerSearchBox().setList(new String[]{
                    "Code", "Nom", "Ville", "Commercial (nom)", "Commercial (code)", "Pr\351nom"
                });
        getCustomerSearchBox().setVal("");
        getCustomerSearchBox().getButtonRight().addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                actionCustomerSearch();
            }
        });
        getCustomerSearchBox().getTextField().addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                actionCustomerSearch();
            }
        });
    }

    private void initCustomerTable() {
        getCustomerTableViewer().setTypes(new Class[]{
                    java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
                });
        getCustomerTableViewer().setLastColumnNotEditable(0);
        getCustomerTableViewer().setCellEditable(false);
        getCustomerTableViewer().setAlternateColor(WIUtil.CUSTOMER_LINE);
        getCustomerTableViewer().setColumnNames(new String[]{
                    "CODE", "NOM", "PRENOM", "VILLE", "COMMERCIAL"
                });
        getCustomerTableViewer().setPreferredColumnSize(new int[]{
                    40, 50, 40, 50, 30
                });
        actionCustomerSearch();
    }

    private void initRealEstateSearch() {
        getRealEstateSearchBox().setList(new String[]{
                    "R\351f", "Genre", "Type", "Ville", "CP"
                });
        getRealEstateSearchBox().setVal("");
        getRealEstateSearchBox().getButtonRight().addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                actionRealEstateSearch();
            }
        });
        getRealEstateSearchBox().getTextField().addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                actionRealEstateSearch();
            }
        });
    }

    private void initRealEstateTable() {
        getRealEstateTableViewer().setTypes(new Class[]{
                    java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
                });
        getRealEstateTableViewer().setLastColumnNotEditable(0);
        getRealEstateTableViewer().setCellEditable(false);
        getRealEstateTableViewer().setColumnNames(new String[]{
                    "REF", "GENRE", "TYPE", "VILLE", "PRIX"
                });
        getRealEstateTableViewer().setPreferredColumnSize(new int[]{
                    40, 50, 40, 50, 30
                });
        actionRealEstateSearch();
    }

    private void initDiaryTable() {
        getDiaryTableViewer().setTypes(new Class[]{
                    java.lang.String.class, javax.swing.Icon.class, java.lang.String.class, java.lang.String.class, javax.swing.Icon.class, java.lang.String.class, java.lang.String.class, javax.swing.Icon.class, java.lang.String.class, java.lang.String.class,
                    javax.swing.Icon.class, java.lang.String.class, java.lang.String.class, javax.swing.Icon.class, java.lang.String.class, java.lang.String.class, javax.swing.Icon.class, java.lang.String.class, java.lang.String.class, javax.swing.Icon.class,
                    java.lang.String.class, java.lang.String.class
                });
        getDiaryTableViewer().setLastColumnNotEditable(0);
        getDiaryTableViewer().setCellEditable(false);
        getDiaryTableViewer().setAlternateColor(WIUtil.DIARY_LINE);
        getDiaryTableViewer().setColumnNames(new String[]{
                    "SEMAINES", "", "SA", "", "", "DI", "", "", "LU", "",
                    "", "MA", "", "", "ME", "", "", "JE", "", "",
                    "VE", ""
                });
        getDiaryTableViewer().setPreferredColumnSize(new int[]{
                    60, 10, 15, 40, 10, 15, 40, 10, 15, 40,
                    10, 15, 40, 10, 15, 40, 10, 15, 40, 10,
                    15, 40
                });
        actionDiarySearch(Integer.parseInt(d.getYear()));
        getDiaryDetailsPanel().getYear().setText(d.getYear());
        getDiaryDetailsPanel().getLast().addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                int last = Integer.parseInt(getDiaryDetailsPanel().getYear().getText()) - 1;
                actionDiarySearch(last);
                getDiaryDetailsPanel().getYear().setText(String.valueOf(last));
            }
        });
        getDiaryDetailsPanel().getNext().addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                int next = Integer.parseInt(getDiaryDetailsPanel().getYear().getText()) + 1;
                actionDiarySearch(next);
                getDiaryDetailsPanel().getYear().setText(String.valueOf(next));
            }
        });
    }

    private void initAvailabilityGUI(boolean modify) {
        if (availabilityGUI == null || availabilityGUI.isClosed()) {
            availabilityGUI = null;
            availabilityGUI = new AvailabilityGUI();
            availabilityGUI.setIconifiable(true);
            availabilityGUI.setResizable(false);
            availabilityGUI.setMaximizable(false);
            availabilityGUI.setClosable(true);
            Dimension screen = param.getDesktop().getSize();
            availabilityGUI.setBounds(screen.width / 2 - 165, screen.height / 2 - 163, 330, 326);
            param.getDesktop().add(availabilityGUI, JLayeredPane.DEFAULT_LAYER);
            availabilityGUI.getSave().addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    actionSave();
                }
            });
            availabilityGUI.getCancel().addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    availabilityGUI.setVisible(false);
                }
            });
        }
        if (availabilityGUI.isIcon()) {
            try {
                availabilityGUI.setIcon(false);
            } catch (PropertyVetoException e) {
                e.printStackTrace();
            }
        }
        if (!availabilityGUI.isVisible()) {
            availabilityGUI.setVisible(true);
        }
        availabilityGUI.initFields();
        if (getDiaryDetailsPanel().getCustomerPanel().getCustomerId() != null) {
            availabilityGUI.setCustomerId(getDiaryDetailsPanel().getCustomerPanel().getCustomerId().toString());
        }
        availabilityGUI.setRealEstateId(getDiaryDetailsPanel().getRealEstatePanel().getIdLabel());
        availabilityGUI.toFront();
    }

    private void actionExit() {
        setVisible(false);
    }

    private void actionRemove() {
        int reponse = JOptionPane.showConfirmDialog(null, "\nEtes-vous certain de vouloir suprimer cette r\351servation ?", "Confirmation", 1, 2, null);
        switch (reponse) {
            case 0: // '\0'
                actionDelete();
            // fall through

            case -1:
            case 1: // '\001'
            case 2: // '\002'
            default:
                return;
        }
    }

    private void actionHelp() {
        BrowserControl.displayURL("www.ifacile.com");
    }

    private void actionModify() {
        setEnabledField(true);
        getIconBarPanel().setEnabledCreate(false);
        getIconBarPanel().setEnabledSave(true);
        getIconBarPanel().setEnabledModify(false);
        getIconBarPanel().setEnabledRemove(true);
        getMenuPanel().getNew().setEnabled(false);
        getMenuPanel().getSave().setEnabled(true);
        getMenuPanel().getModify().setEnabled(false);
        getMenuPanel().getDelete().setEnabled(true);
    }

    private void actionNew() {
        if (getDiaryDetailsPanel().getCustomerPanel().getCustomerId() == null) {
            JOptionPane.showMessageDialog(null, "S\351l\351ctionner un client !");
        } else if (getDiaryDetailsPanel().getRealEstatePanel().getIdLabel().equals("")) {
            JOptionPane.showMessageDialog(null, "S\351l\351ctionner un bien !");
        } else {
            initAvailabilityGUI(false);
            setEnabledField(true);
            getIconBarPanel().setEnabledCreate(false);
            getIconBarPanel().setEnabledSave(true);
            getMenuPanel().getNew().setEnabled(false);
            getMenuPanel().getSave().setEnabled(true);
            create = true;
        }
    }

    private void actionPrint(boolean flag) {
    }

    private void actionSave() {
        if (create) {
            actionCreate();
        } else {
            actionUpdate();
        }
    }

    private void actionCustomerSearch() {
        StringBuffer sql = new StringBuffer();
        if (getCustomerSearchBox().getSelectedIndex() == 3) {
            sql.append("SELECT CUSTOMER.ID, CUSTOMER.LASTNAME, CUSTOMER.FIRSTNAME, CUSTOMER.CITY, SALESPERSON.LASTNAME FROM CUSTOMER, SALESPERSON");
        } else {
            sql.append("SELECT ID, LASTNAME, FIRSTNAME, CITY, SALESPERSONID FROM CUSTOMER");
        }
        switch (getCustomerSearchBox().getSelectedIndex()) {
            case 0: // '\0'
                if (getCustomerSearchBox().getVal().equals("")) {
                    sql.append(" ORDER BY ID");
                } else {
                    sql.append(" WHERE ID LIKE '");
                    sql.append(getCustomerSearchBox().getVal());
                    sql.append("%' ORDER BY ID");
                }
                break;

            case 1: // '\001'
                if (getCustomerSearchBox().getVal().equals("")) {
                    sql.append(" ORDER BY LASTNAME");
                } else {
                    sql.append(" WHERE LASTNAME LIKE '");
                    sql.append(getCustomerSearchBox().getVal());
                    sql.append("%' ORDER BY LASTNAME");
                }
                break;

            case 2: // '\002'
                if (getCustomerSearchBox().getVal().equals("")) {
                    sql.append(" ORDER BY CITY");
                } else {
                    sql.append(" WHERE CITY LIKE '");
                    sql.append(getCustomerSearchBox().getVal());
                    sql.append("%' ORDER BY CITY");
                }
                break;

            case 3: // '\003'
                if (getCustomerSearchBox().getVal().equals("")) {
                    sql.append(" WHERE SALESPERSONID=SALESPERSON.ID");
                    sql.append(" ORDER BY SALESPERSON.LASTNAME");
                } else {
                    sql.append(" WHERE SALESPERSONID=SALESPERSON.ID");
                    sql.append(" AND SALESPERSON.LASTNAME LIKE '");
                    sql.append(getCustomerSearchBox().getVal());
                    sql.append("%' ORDER BY SALESPERSON.LASTNAME");
                }
                break;

            case 4: // '\004'
                if (getCustomerSearchBox().getVal().equals("")) {
                    sql.append(" ORDER BY SALESPERSONID");
                } else {
                    sql.append(" WHERE SALESPERSONID LIKE '");
                    sql.append(getCustomerSearchBox().getVal());
                    sql.append("%' ORDER BY SALESPERSONID");
                }
                break;

            case 5: // '\005'
                if (getCustomerSearchBox().getVal().equals("")) {
                    sql.append(" ORDER BY FIRSTNAME");
                } else {
                    sql.append(" WHERE FIRSTNAME LIKE '");
                    sql.append(getCustomerSearchBox().getVal());
                    sql.append("%' ORDER BY FIRSTNAME");
                }
                break;

            default:
                if (getCustomerSearchBox().getVal().equals("")) {
                    sql.append(" ORDER BY ID");
                } else {
                    sql.append(" WHERE ID LIKE '");
                    sql.append(getCustomerSearchBox().getVal());
                    sql.append("%' ORDER BY ID");
                }
                break;
        }
        Object data[][] = customerCrud.getDataList(sql.toString());
        if (data != null) {
            getCustomerTableViewer().setData(data);
            getCustomerTableViewer().getTable().addMouseListener(new MouseClickCustomerList());
        } else {
            getCustomerTableViewer().setData(getEmptyTable());
        }
    }

    private Object[][] getEmptyTable() {
        Object data[][] = new Object[3][5];
        for (int i = 0; i < data.length; i++) {
            data[i][0] = null;
            if (i == 1) {
                data[i][1] = "AUCUN";
                data[i][2] = "CLIENT";
            } else {
                data[i][1] = null;
                data[i][2] = null;
            }
            data[i][3] = null;
            data[i][4] = null;
        }

        return data;
    }

    private void actionRealEstateSearch() {
        StringBuffer sql = new StringBuffer();
        sql.append("SELECT ID, SORT, TYPE, COUNTY, RENT FROM REALESTATE");
        switch (getRealEstateSearchBox().getSelectedIndex()) {
            case 0: // '\0'
                if (getRealEstateSearchBox().getVal().equals("")) {
                    sql.append(" ORDER BY ID");
                } else {
                    sql.append(" WHERE ID LIKE '");
                    sql.append(getRealEstateSearchBox().getVal());
                    sql.append("%' ORDER BY ID");
                }
                break;

            case 1: // '\001'
                if (getRealEstateSearchBox().getVal().equals("")) {
                    sql.append(" ORDER BY SORT");
                } else {
                    sql.append(" WHERE SORT LIKE '");
                    sql.append(getRealEstateSearchBox().getVal());
                    sql.append("%' ORDER BY SORT");
                }
                break;

            case 2: // '\002'
                if (getRealEstateSearchBox().getVal().equals("")) {
                    sql.append(" ORDER BY TYPE");
                } else {
                    sql.append(" WHERE TYPE LIKE '");
                    sql.append(getRealEstateSearchBox().getVal());
                    sql.append("%' ORDER BY TYPE");
                }
                break;

            case 3: // '\003'
                if (getRealEstateSearchBox().getVal().equals("")) {
                    sql.append(" ORDER BY COUNTY");
                } else {
                    sql.append(" WHERE COUNTY LIKE '");
                    sql.append(getRealEstateSearchBox().getVal());
                    sql.append("%' ORDER BY COUNTY");
                }
                break;

            case 4: // '\004'
                if (getRealEstateSearchBox().getVal().equals("")) {
                    sql.append(" ORDER BY ZIP");
                } else {
                    sql.append(" WHERE ZIP LIKE '");
                    sql.append(getRealEstateSearchBox().getVal());
                    sql.append("%' ORDER BY ZIP");
                }
                break;

            default:
                if (getRealEstateSearchBox().getVal().equals("")) {
                    sql.append(" ORDER BY ID");
                } else {
                    sql.append(" WHERE ID LIKE '");
                    sql.append(getRealEstateSearchBox().getVal());
                    sql.append("%' ORDER BY ID");
                }
                break;
        }
        Object data[][] = customerCrud.getDataList(sql.toString());
        if (data != null) {
            getRealEstateTableViewer().setData(data);
            getRealEstateTableViewer().getTable().addMouseListener(new MouseClickRealEstateList());
        } else {
            getRealEstateTableViewer().setData(getRealEstateEmptyTable());
        }
    }

    private Object[][] getRealEstateEmptyTable() {
        Object data[][] = new Object[3][5];
        for (int i = 0; i < data.length; i++) {
            data[i][0] = null;
            if (i == 1) {
                data[i][1] = "AUCUN";
                data[i][2] = "BIEN";
            } else {
                data[i][1] = null;
                data[i][2] = null;
            }
            data[i][3] = null;
            data[i][4] = null;
        }

        return data;
    }

    private void actionDiarySearch(int y) {
        getDiaryTableViewer().setData(getDiaryYearTable(y));
    }

    private Object[][] getDiaryYearTable(int y) {
        Object data[][] = new Object[54][22];
        int firstDayOfYear = d.getFirstDayOfYear(y);
        int day = 0;
        String year[] = (String[]) null;
        int daysYear = d.getLastDayOfYear(y);
        if (daysYear == 366) {
            year = leapYear;
        } else {
            year = plainYear;
        }
        for (int week = 0; week < 54; week++) {
            if (week == 0) {
                data[week][0] = String.valueOf(week + 1);
                switch (firstDayOfYear) {
                    case 1: // '\001'
                        data[week][4] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][5] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][6] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][7] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][8] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][9] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][10] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][11] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][12] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][13] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][14] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][15] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][16] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][17] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][18] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][19] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][20] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][21] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        break;

                    case 2: // '\002'
                        data[week][7] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][8] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][9] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][10] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][11] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][12] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][13] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][14] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][15] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][16] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][17] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][18] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][19] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][20] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][21] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        break;

                    case 3: // '\003'
                        data[week][10] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][11] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][12] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][13] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][14] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][15] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][16] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][17] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][18] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][19] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][20] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][21] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        break;

                    case 4: // '\004'
                        data[week][13] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][14] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][15] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][16] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][17] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][18] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][19] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][20] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][21] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        break;

                    case 5: // '\005'
                        data[week][16] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][17] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][18] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][19] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][20] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][21] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        break;

                    case 6: // '\006'
                        data[week][19] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][20] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][21] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        break;

                    case 7: // '\007'
                        data[week][1] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][2] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][3] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][4] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][5] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][6] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][7] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][8] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][9] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][10] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][11] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][12] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][13] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][14] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][15] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][16] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][17] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][18] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        data[week][19] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                        data[week][20] = day >= daysYear ? "" : ((Object) (year[day]));
                        data[week][21] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                        break;
                }
            } else {
                data[week][0] = new String(String.valueOf(week + 1));
                data[week][1] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                data[week][2] = day >= daysYear ? "" : ((Object) (year[day]));
                data[week][3] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                data[week][4] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                data[week][5] = day >= daysYear ? "" : ((Object) (year[day]));
                data[week][6] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                data[week][7] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                data[week][8] = day >= daysYear ? "" : ((Object) (year[day]));
                data[week][9] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                data[week][10] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                data[week][11] = day >= daysYear ? "" : ((Object) (year[day]));
                data[week][12] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                data[week][13] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                data[week][14] = day >= daysYear ? "" : ((Object) (year[day]));
                data[week][15] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                data[week][16] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                data[week][17] = day >= daysYear ? "" : ((Object) (year[day]));
                data[week][18] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
                data[week][19] = day >= daysYear ? null : ((Object) (getIcon(day, daysYear)));
                data[week][20] = day >= daysYear ? "" : ((Object) (year[day]));
                data[week][21] = day >= daysYear ? "" : ((Object) (getCustomerId(day++, daysYear)));
            }
        }

        return data;
    }

    private Icon getIcon(int index, int daysYear) {
        if (daysYear == 365) {
            switch (plainYearStatus[index]) {
                case 0: // '\0'
                    return green;

                case 1: // '\001'
                    return orange;

                case 2: // '\002'
                    return red;
            }
            return green;
        }
        switch (leapYearStatus[index]) {
            case 0: // '\0'
                return green;

            case 1: // '\001'
                return orange;

            case 2: // '\002'
                return red;
        }
        return green;
    }

    private String getCustomerId(int index, int daysYear) {
        if (daysYear == 365) {
            return plainYearCustomer[index];
        } else {
            return leapYearCustomer[index];
        }
    }

    private void actionLoad(Integer id) {
        if (id != null) {
            Collection c = crud.readAll(id, 7);
            if (c != null && !c.isEmpty()) {
                ArrayList list = new ArrayList(c);
                for (Iterator it = list.iterator(); it.hasNext(); availabilityDateFill((Availability) it.next()));
                setTitle("Agenda des r\351servations (BIEN REF : " + id + ")");
                getIconBarPanel().setEnabledModify(write);
                getIconBarPanel().setEnabledPrint(true);
                getMenuPanel().getModify().setEnabled(write);
                getMenuPanel().getPrint().setEnabled(true);
            }
        }
    }

    private void availabilityDateFill(Availability availability) {
        int beginDay = d.getDayOfTheYear(availability.getBeginDate());
        int endDay = d.getDayOfTheYear(availability.getEndDate());
        int days = endDay - beginDay;
        if (d.getLastDayOfYear(Integer.parseInt(availability.getBeginDate().substring(6))) == 365) {
            for (int i = 0; i < days; i++) {
                if (availability.getConfirmed().equals("RESERVER")) {
                    plainYearStatus[beginDay - 1] = 1;
                    plainYearCustomer[beginDay - 1] = availability.getCustomerId().toString();
                } else if (availability.getConfirmed().equals("CONFIRMER")) {
                    plainYearStatus[beginDay - 1] = 2;
                    plainYearCustomer[beginDay - 1] = availability.getCustomerId().toString();
                }
                beginDay++;
            }

        } else {
            for (int i = 0; i < days; i++) {
                if (availability.getConfirmed().equals("RESERVER")) {
                    leapYearStatus[beginDay - 1] = 1;
                    leapYearCustomer[beginDay - 1] = availability.getCustomerId().toString();
                } else if (availability.getConfirmed().equals("CONFIRMER")) {
                    leapYearStatus[beginDay - 1] = 2;
                    leapYearCustomer[beginDay - 1] = availability.getCustomerId().toString();
                }
                beginDay++;
            }

        }
    }

    private void actionCustomerLoad(String id) {
        if (id != null) {
            Customer customer = (Customer) crud.read(new Integer(id), 8);
            if (customer != null) {
                getDiaryDetailsPanel().getCustomerPanel().setCustomerId(customer.getId());
                getDiaryDetailsPanel().getCustomerPanel().setStatusLabel(customer.getStatus());
                getDiaryDetailsPanel().getCustomerPanel().setLastnameLabel(customer.getLastname());
                getDiaryDetailsPanel().getCustomerPanel().setFirstnameLabel(customer.getFirstname());
                getDiaryDetailsPanel().getCustomerPanel().setAddrLn1Label(customer.getAddrLn1());
                getDiaryDetailsPanel().getCustomerPanel().setAddrLn2Label(customer.getAddrLn2());
                getDiaryDetailsPanel().getCustomerPanel().setZipLabel(customer.getZip());
                getDiaryDetailsPanel().getCustomerPanel().setCityLabel(customer.getCity());
                getDiaryDetailsPanel().getCustomerPanel().setTelLabel(customer.getTel());
                getDiaryDetailsPanel().getCustomerPanel().setCelLabel(customer.getCel());
                getDiaryDetailsPanel().getCustomerPanel().setFaxLabel(customer.getFax());
                getDiaryDetailsPanel().getCustomerPanel().setEmailLabel(customer.getEmail());
            }
        }
    }

    public void actionRealEstateLoad(String id) {
        if (id != null) {
            RealEstate realEstate = (RealEstate) crud.read(new Integer(id), 4);
            if (realEstate != null) {
                getDiaryDetailsPanel().getRealEstatePanel().setIdLabel(realEstate.getId().toString());
                getDiaryDetailsPanel().getRealEstatePanel().setRefInternalLabel(realEstate.getRefInternal());
                getDiaryDetailsPanel().getRealEstatePanel().setAddrLn1Label(realEstate.getAddrLn1());
                getDiaryDetailsPanel().getRealEstatePanel().setAddrLn2Label(realEstate.getAddrLn2());
                getDiaryDetailsPanel().getRealEstatePanel().setSortLabel(realEstate.getSort());
                getDiaryDetailsPanel().getRealEstatePanel().setTypeLabel(realEstate.getType());
                getDiaryDetailsPanel().getRealEstatePanel().setZipLabel(realEstate.getZip());
                getDiaryDetailsPanel().getRealEstatePanel().setCityLabel(realEstate.getCounty());
                getDiaryDetailsPanel().getRealEstatePanel().setRentLabel(realEstate.getRent().toString());
                getDiaryDetailsPanel().getRealEstatePanel().setDepositLabel(realEstate.getDeposit().toString());
                StringBuffer sb = new StringBuffer("\tDETAILS DU BIEN");
                sb.append("\nStanding : \t" + realEstate.getStanding());
                sb.append("\nEtat : \t" + realEstate.getCondition());
                sb.append("\nMeubl\351 : \t" + realEstate.getFurnished());
                sb.append("\nChauffage : \t" + realEstate.getHeating());
                sb.append("\nSols : \t" + realEstate.getStylefloor());
                sb.append("\nMurs : \t" + realEstate.getWalls());
                sb.append("\nDublex : \t" + realEstate.getDuplex());
                sb.append("\nChemin\351e : \t" + realEstate.getFireplace());
                sb.append("\nPlacards : \t" + realEstate.getCupboard());
                sb.append("\nLit(s) : \t" + realEstate.getBed());
                sb.append("\nTV : \t" + realEstate.getTv());
                sb.append("\n");
                sb.append("\nHall : \t" + realEstate.getHall() + " (surface : " + realEstate.getSHall() + "m\262)");
                sb.append("\nS\351jour : \t" + realEstate.getLivingroom() + " (surface : " + realEstate.getSLivingroom() + "m\262)");
                sb.append("\nChambre(s) : \t" + realEstate.getBedroom() + " (surface : " + realEstate.getSRoom() + "m\262)");
                sb.append("\nCuisine : \t" + realEstate.getKitchen() + " (surface : " + realEstate.getSKitchen() + "m\262)");
                sb.append("\nSDB : \t" + realEstate.getBathroom());
                sb.append("\nWC : \t" + realEstate.getRestroom());
                sb.append("\nDouche : \t" + realEstate.getShower());
                sb.append("\nMezzanine : \t" + realEstate.getMezzanine() + " (surface : " + realEstate.getSMezzanine() + "m\262)");
                sb.append("\nLoggia : \t" + realEstate.getLoggia() + " (surface : " + realEstate.getSLoggia() + "m\262)");
                sb.append("\nCellier : \t" + realEstate.getCellarWine() + " (surface : " + realEstate.getSCellarWine() + "m\262)");
                sb.append("\nCave : \t" + realEstate.getCellar() + " (surface : " + realEstate.getSCellar() + "m\262)");
                sb.append("\nSurface hab. : \t" + realEstate.getSurfaceFloor() + "m\262");
                sb.append("\n");
                sb.append("\nBalcon : \t" + realEstate.getBalcony() + " (surface : " + realEstate.getSBalcony() + "m\262)");
                sb.append("\nTerrasse : \t" + realEstate.getRoofgarden() + " (surface : " + realEstate.getSRoofgarden() + "m\262)");
                sb.append("\nJardin : \t" + realEstate.getGarden() + " (surface : " + realEstate.getSurfaceGround() + "m\262)");
                sb.append("\nPiscine : \t" + realEstate.getPool());
                sb.append("\nParking : \t" + realEstate.getParking());
                sb.append("\nGarage : \t" + realEstate.getGarage() + " (surface : " + realEstate.getSGarage() + "m\262)");
                getDiaryDetailsPanel().getRealEstatePanel().setDetailsTextArea(sb.toString());
                actionLoad(realEstate.getId());
                actionDiarySearch(Integer.parseInt(getDiaryDetailsPanel().getYear().getText()));
            }
        }
    }

    private void actionUpdate() {
        if (verifyRequirement()) {
            initField();
            availabilityGUI.setVisible(false);
        }
    }

    private void actionCreate() {
        if (verifyRequirement()) {
            Integer pk = crud.create(7);
            if (pk != null) {
                Availability av = (Availability) crud.read(pk, 7);
                if (av != null) {
                    av.setBeginDate(availabilityGUI.getBeginDate());
                    av.setEndDate(availabilityGUI.getEndDate());
                    av.setConfirmed(availabilityGUI.getConfirmed());
                    av.setCustomerId(new Integer(availabilityGUI.getCustomerId()));
                    av.setRealEstateId(new Integer(availabilityGUI.getRealEstateId()));
                    av.setOption(availabilityGUI.getOption());
                    av.setNotes(availabilityGUI.getNotes());
                    av.setLastUser(param.getUserId().toString());
                    crud.update(av, 7);
                }
            }
            initField();
            availabilityGUI.setVisible(false);
        }
    }

    private void actionDelete() {
        initField();
    }

    private boolean verifyRequirement() {
        if (!d.isValid(availabilityGUI.getBeginDate())) {
            JOptionPane.showMessageDialog(null, "Date d\351but invalide !");
            return false;
        }
        if (!d.isValid(availabilityGUI.getEndDate())) {
            JOptionPane.showMessageDialog(null, "Date fin invalide !");
            return false;
        }
        if (!availabilityGUI.getBeginDate().substring(6).equals(getDiaryDetailsPanel().getYear().getText())) {
            JOptionPane.showMessageDialog(null, "Erreur d'ann\351e sur la date d\351but !\n(seule l'ann\351e s\351l\351ctionn\351e sur l'agenda est valide)");
            return false;
        }
        if (!availabilityGUI.getEndDate().substring(6).equals(getDiaryDetailsPanel().getYear().getText())) {
            JOptionPane.showMessageDialog(null, "Erreur d'ann\351e sur la date fin !\n(seule l'ann\351e s\351l\351ctionn\351e sur l'agenda est valide)");
            return false;
        }
        if (d.compareTo(availabilityGUI.getBeginDate(), availabilityGUI.getEndDate()) > 0) {
            JOptionPane.showMessageDialog(null, "La date de d\351but ne peu pas \352tre\nplus grande que la date de fin");
            return false;
        }
        if (availabilityGUI.getConfirmed().equals("")) {
            JOptionPane.showMessageDialog(null, "S\351l\351ctionner un etat pour la r\351servation !\n(RESERVER ou CONFIRMER)");
            return false;
        } else {
            return true;
        }
    }
    private ObjectCRUD crud;
    private Parameter param;
    private CustomerCRUD customerCrud;
    private boolean create;
    private WIDate d;
    private boolean write;
    private String plainYear[] = {
        "  1", "  2", "  3", "  4", "  5", "  6", "  7", "  8", "  9", "10",
        "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
        "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
        "31", "  1", "  2", "  3", "  4", "  5", "  6", "  7", "  8", "  9",
        "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
        "20", "21", "22", "23", "24", "25", "26", "27", "28", "  1",
        "  2", "  3", "  4", "  5", "  6", "  7", "  8", "  9", "10", "11",
        "12", "13", "14", "15", "16", "17", "18", "19", "20", "21",
        "22", "23", "24", "25", "26", "27", "28", "29", "30", "31",
        "  1", "  2", "  3", "  4", "  5", "  6", "  7", "  8", "  9", "10",
        "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
        "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
        "  1", "  2", "  3", "  4", "  5", "  6", "  7", "  8", "  9", "10",
        "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
        "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
        "31", "  1", "  2", "  3", "  4", "  5", "  6", "  7", "  8", "  9",
        "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
        "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
        "30", "  1", "  2", "  3", "  4", "  5", "  6", "  7", "  8", "  9",
        "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
        "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
        "30", "31", "  1", "  2", "  3", "  4", "  5", "  6", "  7", "  8",
        "  9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
        "19", "20", "21", "22", "23", "24", "25", "26", "27", "28",
        "29", "30", "31", "  1", "  2", "  3", "  4", "  5", "  6", "  7",
        "  8", "  9", "10", "11", "12", "13", "14", "15", "16", "17",
        "18", "19", "20", "21", "22", "23", "24", "25", "26", "27",
        "28", "29", "30", "  1", "  2", "  3", "  4", "  5", "  6", "  7",
        "  8", "  9", "10", "11", "12", "13", "14", "15", "16", "17",
        "18", "19", "20", "21", "22", "23", "24", "25", "26", "27",
        "28", "29", "30", "31", "  1", "  2", "  3", "  4", "  5", "  6",
        "  7", "  8", "  9", "10", "11", "12", "13", "14", "15", "16",
        "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
        "27", "28", "29", "30", "  1", "  2", "  3", "  4", "  5", "  6",
        "  7", "  8", "  9", "10", "11", "12", "13", "14", "15", "16",
        "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
        "27", "28", "29", "30", "31"
    };
    private String leapYear[] = {
        "  1", "  2", "  3", "  4", "  5", "  6", "  7", "  8", "  9", "10",
        "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
        "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
        "31", "  1", "  2", "  3", "  4", "  5", "  6", "  7", "  8", "  9",
        "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
        "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
        "  1", "  2", "  3", "  4", "  5", "  6", "  7", "  8", "  9", "10",
        "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
        "21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
        "31", "  1", "  2", "  3", "  4", "  5", "  6", "  7", "  8", "  9",
        "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
        "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
        "30", "  1", "  2", "  3", "  4", "  5", "  6", "  7", "  8", "  9",
        "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
        "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
        "30", "31", "  1", "  2", "  3", "  4", "  5", "  6", "  7", "  8",
        "  9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
        "19", "20", "21", "22", "23", "24", "25", "26", "27", "28",
        "29", "30", "  1", "  2", "  3", "  4", "  5", "  6", "  7", "  8",
        "  9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
        "19", "20", "21", "22", "23", "24", "25", "26", "27", "28",
        "29", "30", "31", "  1", "  2", "  3", "  4", "  5", "  6", "  7",
        "  8", "  9", "10", "11", "12", "13", "14", "15", "16", "17",
        "18", "19", "20", "21", "22", "23", "24", "25", "26", "27",
        "28", "29", "30", "31", "  1", "  2", "  3", "  4", "  5", "  6",
        "  7", "  8", "  9", "10", "11", "12", "13", "14", "15", "16",
        "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
        "27", "28", "29", "30", "  1", "  2", "  3", "  4", "  5", "  6",
        "  7", "  8", "  9", "10", "11", "12", "13", "14", "15", "16",
        "17", "18", "19", "20", "21", "22", "23", "24", "25", "26",
        "27", "28", "29", "30", "31", "  1", "  2", "  3", "  4", "  5",
        "  6", "  7", "  8", "  9", "10", "11", "12", "13", "14", "15",
        "16", "17", "18", "19", "20", "21", "22", "23", "24", "25",
        "26", "27", "28", "29", "30", "  1", "  2", "  3", "  4", "  5",
        "  6", "  7", "  8", "  9", "10", "11", "12", "13", "14", "15",
        "16", "17", "18", "19", "20", "21", "22", "23", "24", "25",
        "26", "27", "28", "29", "30", "31"
    };
    private int plainYearStatus[];
    private int leapYearStatus[];
    private String plainYearCustomer[];
    private String leapYearCustomer[];
    private Icon green;
    private Icon orange;
    private Icon red;
    private AvailabilityGUI availabilityGUI;
}
